<template>
    <div class="reportFormPage" v-if="show">
        <div class="report-dom">
            <el-row>
                <el-col :span="5" :offset="19">
                    <div class="pageNumBox">
                        <span>第</span>
                        <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
                        <span>页，共</span>
                        <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
                        <span>页</span>
                    </div>
                </el-col>
            </el-row>
            <div class="topTwoBox">
                <div class="centerName">{{ this.form.baobmc }}</div>
                <div class="codeText">
                    <tr v-for="(item, index) in form.baobbhList">{{ item }}</tr>
                </div>
            </div>
            <div class="threeTopBox">
                <div class="left-border">
                    <div class="box-title">检测单位名称：</div>
                    <div class>{{ form.jiancdwmc }}</div>
                </div>
                <div class="right-border">
                    <span>记录编号：</span>
                    <span class="placeholder">{{ form.jilbh }}</span>
                </div>
            </div>
            <!-- .........................1111111111111111111111111111111......................................................... -->
            <div class="table-border">
                <table height="220px" class="top-table">
                    <tbody>
                    <tr>
                        <td height="30" align="center" width="15%">
                            <span style="width: 90px; display: inline-block">工程名称</span>
                        </td>
                        <td width="35%" class="text-center">
                            <span>{{ form.gongcmc }}</span>
                        </td>
                        <td align="center" width="15%">
                            <span style="width: 90px; display: inline-block">工程部位/用途</span>
                        </td>
                        <td width="35%" class="text-center">
                            <span>{{ form.gongcbwyt }}</span>
                        </td>
                    </tr>
                    <tr>
                        <td height="50" align="center">样品信息</td>
                        <td class="specimen-border" colspan="3">
                            <span>样品名称：</span>
                            <span :class="{ 'placeholder': !form.yangpmc }">{{ form.yangpmc }}</span>
                            <span>；样品编号：</span>
                            <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                            <span>；样品数量：</span>
                            <span :class="{ 'placeholder': !form.yangpsl }">{{ form.yangpsl }}</span>
                            <span>；样品状态：</span>
                            <span :class="{ 'placeholder': !form.yangpzt }">{{ form.yangpzt }}</span>
                            <span>；来样时间：</span>
                            <span :class="{ 'placeholder': !form.yangpsj }">{{ form.yangpsj }}</span>
                        </td>
                    </tr>

                    <tr>
                        <td height="25" align="center" width="15%">
                            <span style="width: 90px; display: inline-block">试验检测日期</span>
                        </td>
                         <!-- <td width="35%" class="text-center">{{ form.shiyjcrq }}</td> -->                                            
 <td width="35%" class="text-center">
      <el-input v-model="form.shiyjcrq" />
</td>
                        <td align="center" width="15%">
                            <span style="width: 90px; display: inline-block">试验条件</span>
                        </td>
                        <td v-if="isPdf" width="35%">
                            温度：
                            <span style="display: inline-block; width: 10%;">{{ form.shiytjwd }}</span>
                            ℃；湿度：
                            <span style="display: inline-block; width: 10%;">{{ form.shiytjsd }}</span>%RH
                        </td>
                        <td v-else width="35%">
                            温度：
                            <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjwd" style="width: 15%"/>
                            ℃；湿度：
                            <el-input :type="isPdf ? 'string' : 'number'" v-model="form.shiytjsd" style="width: 15%"/>
                            %RH
                        </td>
                    </tr>

                    <tr>
                        <td height="50" align="center" width="15%">
                            <span style="width: 90px; display: inline-block">检测依据</span>
                        </td>
                        <td width="35%">
                            <span v-if="isPdf">{{ form.jiancyj }}</span>
                            <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark"
                                      @dblclick.native="showBsJiancyjView" readonly/>
                        </td>
                        <td align="center" width="15%">
                            <span style="width: 90px; display: inline-block">判定依据</span>
                        </td>
                        <td width="35%">
                            <span v-if="isPdf">{{ form.pandyj }}</span>
                            <el-input v-else type="textarea" v-model="form.pandyj" :rows="2"
                                      @dblclick.native="showBsJudgeBaseView"
                                      @focus="handleFocus('pandyj')" class="mark"/>
                        </td>
                    </tr>
                    <tr class="bottom-border">
                        <td height="50" align="center">
                            <div>主要仪器设备</div>
                            <div>名称及编号</div>
                        </td>
                        <td colspan="3">
                            <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                            <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh"
                                      class="height100 width100 mark"
                                      @dblclick.native="showBsInstrumentView" readonly></el-input>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <!-- .................................22222222222222222222222222222222............................................... -->
                <table height="610px" class="middle-table">
                    <tbody>
                    <tr trindex="0">
                        <td rowspan="3">
                            <div>筛前试样总质量m<sub>3</sub>(g)</div>
                        </td>
                        <td colspan="4">
                            <div>第1组</div>
                        </td>
                        <td colspan="4">
                            <div>第2组</div>
                        </td>
                        <td rowspan="4">
                            <div>平均通过百分率(%)</div>
                        </td>
                        <td rowspan="3" colspan="2">
                            <div>规定级配范围(%)</div>
                        </td>
                    </tr>
                    <tr trindex="1">
                        <td>
                            <div>称量次数</div>
                        </td>
                        <td colspan="3">
                            <div>{{ this.form.chenglcsItem1 }}</div>
                        </td>
                        <td>
                            <div>称量次数</div>
                        </td>
                        <td colspan="3">
                            <div>{{ this.form.chenglcsItem2 }}</div>
                        </td>
                    </tr>
                    <tr trindex="2">
                        <td>
                            <div>质量m<sub>0</sub></div>
                        </td>
                        <td colspan="3">
                            <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.zhilItem1"
                                      @change="zhilItemChange(1)" @keydown.native="handleKeyDown($event, 0, 0)"
                                      :ref="'0_0'"/>
                        </td>
                        <td>
                            <div>质量m<sub>0</sub></div>
                        </td>
                        <td colspan="3">
                            <el-input :type="isPdf ? 'string' : 'number'" tabindex="200" v-model="form.zhilItem2"
                                      @change="zhilItemChange(2)" @keydown.native="handleKeyDown($event, 0, 1)"
                                      :ref="'0_1'"/>
                        </td>
                    </tr>
                    <tr trindex="4">
                        <td class="td-left">
                            <div>筛孔尺寸(mm)</div>
                        </td>
                        <td class="td1">
                            <div>筛上质量m<sub>i</sub>(g)</div>
                        </td>
                        <td class="td1">
                            <div>分计筛余(%)</div>
                        </td>
                        <td class="td1">
                            <div>累计筛余(%)</div>
                        </td>
                        <td class="td1">
                            <div>通过百分率(%)</div>
                        </td>
                        <td class="td1">
                            <div>筛上质量m<sub>i</sub>(g)</div>
                        </td>
                        <td class="td1">
                            <div>分计筛余(%)</div>
                        </td>
                        <td class="td1">
                            <div>累计筛余(%)</div>
                        </td>
                        <td class="td1">
                            <div>通过百分率(%)</div>
                        </td>
                        <td class="td1">
                            <div>最大值</div>
                        </td>
                        <td class="td1">
                            <div>最小值</div>
                        </td>
                    </tr>
                    <tr v-for="(item, index) in form.detailList" :key="index">
                        <td class="td1">
                            <el-input type="text" tabindex="200"
                                      v-model="item.shaikcc"
                                      @change="shaikccChange()"
                                      @keydown.native="handleKeyDown($event, index + 1, 0)"
                                      @paste.native="handlePasteDetailList($event,  index, 0)"
                                      :ref="`${index + 1}_0`"/>
                        </td>
                        <td class="td1">
                            <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                                      v-model="item.shaiszlItem1"
                                      @change="detailChange(1)"
                                      @keydown.native="handleKeyDown($event, index + 1, 1)"
                                      @paste.native="handlePasteDetailList($event,  index, 1)"
                                      :ref="`${index + 1}_1`"/>
                        </td>
                        <td class="td1">
                            <div>{{ item.fenjsyItem1 }}</div>
                        </td>
                        <td class="td1">
                            <div>{{ item.leijsyItem1 }}</div>
                        </td>
                        <td class="td1">
                            <div>{{ item.tonggbflItem1 }}</div>
                        </td>
                        <td class="td1">
                            <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                                      v-model="item.shaiszlItem2"
                                      @change="detailChange(2)"
                                      @keydown.native="handleKeyDown($event, index + 1, 2)"
                                      @paste.native="handlePasteDetailList($event,  index, 2)"
                                      :ref="`${index + 1}_2`"/>
                        </td>
                        <td class="td1">
                            <div>{{ item.fenjsyItem2 }}</div>
                        </td>
                        <td class="td1">
                            <div>{{ item.leijsyItem2 }}</div>
                        </td>
                        <td class="td1">
                            <div>{{ item.tonggbflItem2 }}</div>
                        </td>
                        <td class="td1">
                            <div>{{ item.leijsybflPzh }}</div>
                        </td>
                        <td class="td1">
                            <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                                      v-model="item.guidfwMax"
                                      @change="maxChange()"
                                      @keydown.native="handleKeyDown($event, index + 1, 3)"
                                      @paste.native="handlePasteDetailList($event,  index, 3)"
                                      :ref="`${index + 1}_3`"/>
                        </td>
                        <td class="td1">
                            <el-input :type="isPdf ? 'string' : 'number'" tabindex="200"
                                      v-model="item.guidfwMin"
                                      @change="maxChange()"
                                      @keydown.native="handleKeyDown($event, index + 1, 4)"
                                      @paste.native="handlePasteDetailList($event,  index, 4)"
                                      :ref="`${index + 1}_4`"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div>筛分后总质量(g)</div>
                        </td>
                        <td colspan="5">
                            <div>{{ this.form.shaifhzzlItem1 }}</div>
                        </td>
                        <td colspan="6">
                            <div>{{ this.form.shaifhzzlItem2 }}</div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div>损耗m<sub>5</sub>(g)</div>
                        </td>
                        <td colspan="5">
                            <div>{{ this.form.sunhItem1 }}</div>
                        </td>
                        <td colspan="6">
                            <div>{{ this.form.sunhItem2 }}</div>
                        </td>
                    </tr>
                    <tr height="25">
                        <td>
                            <div>损耗率（%）</div>
                        </td>
                        <td colspan="5">
                            <div>{{ this.form.sunhlItem1 }}</div>
                        </td>
                        <td colspan="6">
                            <div>{{ this.form.sunhlItem2 }}</div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="12" width="100%" height="100px" class="echarts-border">
                            <table-line-log-more-chart :className="'echarts-border'" :chartData="chartData" :yMin="0"
                                                       :yMax="100"
                                                       :xType="'category'"></table-line-log-more-chart>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <!-- .....................................................33333333333333333................................................... -->
                <table height="60px" class="bottom-table">
                    <tr>
                        <td>
                            <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
                            <el-input v-else type="textarea" :rows="2" v-model="form.fujsm"
                                      @focus="handleFocus('fujsm')"/>
                        </td>
                    </tr>
                </table>
            </div>
            <!-- .................................44444444444............................................. -->
            <table height="22px" class="transparent">
                <tbody>
                <tr>
                    <td width="10%" align="right">检测：</td>
                    <td width="15%" align="left">
                        <!-- {{this.form.jiancr}} -->
                    </td>
                    <td width="10%" align="right">记录：</td>
                    <td width="15%" align="left">
                        <!-- {{this.form.jilr}} -->
                    </td>
                    <td width="10%" align="right">复核：</td>
                    <td align="left" width="15%">
                        <!-- {{this.form.fuhr}} -->
                    </td>
                    <td width="10%">日期：</td>
                    <td align="left" width="15%">
                        <div style="display: inline-block; margin-right: 30px;">年</div>
                        <div style="display: inline-block; margin-right: 30px;">月</div>
                        <div style="display: inline-block;">日</div>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
        <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
        <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
        <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
    </div>
</template>

<script>
import {handleFocus, emptyConvert, uniqueStr, handleKeyDown, handlePaste} from "@/views/reportForms/utils";
import {getCjlsfgsfjlbBsInfo} from "@/api/report_jl/cjl";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import TableLineLogMoreChart from "@/views/reportForms/components/TableLineLogMoreChart.vue";
import {orderBy} from "lodash";
import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";

export default {
    name: "cjlsfgsfjlbTable",
    components: {
        BsInstrumentView,
        BsJiancyjView,
        BsJudgeBaseView,
        TableLineLogMoreChart
    },
    props: {
        //   default: () => ""
        excelId: {
            type: [String, Number],
            default: () => ""
        },
        syType: {
            type: [String, Number],
            default: () => ""
        },
        page: {
            type: Number,
            default: () => 0
        },
        isPdf: {
            type: Boolean,
            default: () => false
        },
        printEmpty: {
            type: Boolean,
            default: () => false
        }
    },
    data() {
        return {
            form: {
                detailList: [],
                baobbhList: []
            },
            show: false,
            showQyxx: false,
            backBgz: {},
            chartData: {
                xName: "筛孔尺寸（mm）",
                yName: "通过百分率（%）",
                seriesData: [],
                time: ""
            }
        };
    },
    created() {
        this.init();
    },
    watch: {
        isPdf(newVal, oldVal) {
            this.form = {...emptyConvert(this.form, newVal)};
        }
    },
    methods: {
        // 根据报表id获取当前报表信息
        init() {
            this.show = false;
            getCjlsfgsfjlbBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
                this.form = response.data;
                if (!this.form.fujsm) {
                    this.form.fujsm = "附加声明：";
                }
                this.setInitialValue();
                if (!this.form.detailList || this.form.detailList.length <= 0) {
                    this.getDetailList();
                }
                this.show = true;
                this.$nextTick(() => {
                    this.setEcharts();
                });
            });
        },
        // 设置初始值
        setInitialValue() {
            if (this.form) {
                this.form.baobmc = this.form.baobmc || "粗集料筛分试验检测记录表（干筛法）";
                this.form.baobbh = this.form.baobbh || "JGLQ02001a";
                this.$set(this.form, "baobbhList", []);
                this.form.baobbhList = ["JGLQ02001a"];
                this.form.chenglcsItem1 = this.form.chenglcsItem1 || "1";
                this.form.chenglcsItem2 = this.form.chenglcsItem2 || "2";
            }
        },
        // 假数据
        getDetailList() {
            this.$set(this.form, "detailList", []);
            for (let i = 0; i < 10; i++) {
                this.form.detailList.push({
                    detailId: null,
                    excelId: this.excelId,
                    shaikcc: "",
                    chenglcsItem1: null,
                    zhilItem1: null,
                    shaiszlItem1: null,
                    fenjsyItem1: null,
                    leijsyItem1: null,
                    tonggbflItem1: null,
                    chenglcsItem2: null,
                    zhilItem2: null,
                    shaiszlItem2: null,
                    fenjsyItem2: null,
                    leijsyItem2: null,
                    tonggbflItem2: null,
                    leijsybflPzh: null,
                    guidfwMax: null,
                    guidfwMin: null
                });
            }
        },

        // 显示仪器列表
        showBsInstrumentView() {
            this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
        },
        // 仪器选择
        selectInstrument(info) {
            this.form.zhuyyqsbmcjbh = info.label;
            this.form.shebIds = info.ids;
            Bus.$emit("setCjlBgZhuyyqsbmcjbh", {zhuyyqsbmcjbh: this.form.zhuyyqsbmcjbh, shebIds: this.form.shebIds});
        },
        // 显示检测依据列表
        showBsJiancyjView() {
            this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
        },
        // 检测依据选择
        selectJiancyj(info) {
            this.form.jiancyj = info.label;
            this.form.jiancyjIds = info.ids;
            Bus.$emit("setCjlBgJiancyj", {jiancyj: this.form.jiancyj, jiancyjIds: this.form.jiancyjIds});
        },
        // 显示判定依据列表
        showBsJudgeBaseView() {
            this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
        },
        // 判断依据选择
        selectJudge(info) {
            if (!this.form.pandyj) {
                this.form.pandyj = info.label;
                return;
            }
            if (info && info.label) {
                this.form.pandyj += "、" + info.label;
            }
        },
        submitForm() {
            return this.form;
        },
        handleFocus(event) {
            handleFocus(event, this.page, this.form[event]);
        },
        zhilItemChange(index) {
            this.detailChange(index);
        },
        shaikccChange() {
            this.detailChange(1, false);
            this.detailChange(2, false);
            this.backBgzFun();
        },
        detailChange(type, isbackBg = true) {
            this.computeShaifhzzl(type);
            this.computeSunhItem(type);
            this.computeSunhlItem(type);
            this.computeItem(type);
            if (isbackBg) {
                this.backBgzFun();
            }
            this.setEcharts();
        },
        // 计算各项数据
        computeItem(type) {
            // 100*d/(A+m)
            const A = this.form["shaifhzzlItem" + type];
            const info = this.form.detailList.find((item) => item.shaikcc && item.shaikcc.indexOf("底") > -1);
            if (!info) {
                this.form.detailList.forEach((item) => {
                    item["fenjsyItem" + type] = null;
                    item["leijsyItem" + type] = null;
                    item["tonggbflItem" + type] = null;
                    item.leijsybflPzh = null;
                });
                return;
            }
            const m = info["shaiszlItem" + type] || "0";
            const C = decimal.add(A, m);
            // 累计筛余
            let leijsyItem = 0;
            this.form.detailList.forEach((item, index) => {
                if (!C || !item.shaikcc || !item["shaiszlItem" + type]) {
                    item["fenjsyItem" + type] = null;
                    item["leijsyItem" + type] = null;
                    item["tonggbflItem" + type] = null;
                    item.leijsybflPzh = null;
                    return;
                }
                item["fenjsyItem" + type] = decimal.divide(decimal.multiply(item["shaiszlItem" + type], 100), C, 1);
                item["leijsyItem" + type] = decimal.add(leijsyItem, item["fenjsyItem" + type], 1);
                item["tonggbflItem" + type] = decimal.subtract(100, item["leijsyItem" + type], 1);
                leijsyItem = item["leijsyItem" + type];
                // 求平均值
                if (item.tonggbflItem1 && item.tonggbflItem2) {
                    item.leijsybflPzh = decimal.divide(decimal.add(item.tonggbflItem1, item.tonggbflItem2), 2, 2);
                } else {
                    item.leijsybflPzh = null;
                }
                if (item.shaikcc && item.shaikcc.includes("底")) {
                    item["tonggbflItem" + type] = null;
                    item.leijsybflPzh = null;
                }
            });
        },
        // 计算筛分后总质量
        computeShaifhzzl(type) {
            // A=d+e+f+g+h....+l
            const newVal = this.form.detailList;
            let sum = 0;
            newVal.forEach((item) => {
                if (item.shaikcc && item.shaikcc.indexOf("底") == -1) {
                    sum = decimal.add(sum, item["shaiszlItem" + type] || 0, 1);
                }
            });
            this.form["shaifhzzlItem" + type] = sum;
        },
        // 计算损耗
        computeSunhItem(type) {
            // a-m-A
            const A = this.form["shaifhzzlItem" + type];
            const info = this.form.detailList.find((item) => item.shaikcc && item.shaikcc.indexOf("底") > -1);
            if (!info) {
                this.form["sunhItem" + type] = null;
                return;
            }
            const m = info["shaiszlItem" + type] || "0";
            if (!this.form["zhilItem" + type] || !m || !A) {
                this.form["sunhItem" + type] = null;
                return;
            }
            // a-m-A
            this.form["sunhItem" + type] = decimal.subtract(decimal.subtract(this.form["zhilItem" + type], m, 1), A, 1);
        },
        // 计算损耗率
        computeSunhlItem(type) {
            const a = this.form["zhilItem" + type];
            const b = this.form["sunhItem" + type];
            if (!a || !b) {
                this.form["sunhlItem" + type] = "";
                return;
            }
            // 100*(a-m-A)/a
            this.form["sunhlItem" + type] = decimal.divide(decimal.multiply(b, 100), a);
        },
        maxChange() {
            this.backBgzFun();
            this.setEcharts();
        },
        // 返回报告引入值
        backBgzFun() {
            const list = this.form.detailList.map((item, index) => {
                return {
                    skcc: item.shaikcc,
                    scz: item.leijsybflPzh,
                    max: item.guidfwMax || "-",
                    min: item.guidfwMin || "-"
                };
            });
            Bus.$emit("setCjlBgGanS", list);
        },
        // 损耗率
        computeShl() {
            let a1,
                m1,
                a2,
                m2,
                k1,
                k2,
                e1,
                e2 = 0;
            for (let i = 0; i < this.form.detailList.length; i++) {
                a1 = decimal.add(a1, this.form.detailList[i].shaiszlItem1 || 0);
                a2 = decimal.add(a2, this.form.detailList[i].shaiszlItem2 || 0);
                if (this.form.detailList[i].shaikcc && this.form.detailList[i].shaikcc.indexOf("底") != -1) {
                    m1 = this.form.detailList[i].shaiszlItem1 || 0;
                    m2 = this.form.detailList[i].shaiszlItem2 || 0;
                }
            }
            this.form.sunhItem1 = m1;
            this.form.sunhItem2 = m2;

            for (let i = 0; i < this.form.detailList.length; i++) {
                this.form.detailList[i].zhilItem1 = this.form.zhilItem1;
                this.form.detailList[i].zhilItem2 = this.form.zhilItem2;
                this.form.detailList[i].sunhItem1 = this.form.sunhItem1;
                this.form.detailList[i].sunhItem2 = this.form.sunhItem2;
                // 筛分后总质量-从表
                this.form.detailList[i].shaifhzzlItem1 = a1;
                this.form.detailList[i].shaifhzzlItem2 = a2;
                // 损耗率
                if (this.form.detailList[i].zhilItem1 && this.form.detailList[i].zhilItem1 != 0) {
                    const b = decimal.subtract(this.form.detailList[i].zhilItem1 || 0, this.form.detailList[i].sunhItem1 || 0);
                    const c = decimal.subtract(b, a1);
                    const d = decimal.multiply(100, c);
                    e1 = decimal.divide(d, this.form.detailList[i].zhilItem1);
                    this.form.detailList[i].sunhlItem1 = e1;
                } else {
                    this.form.detailList[i].sunhlItem1 = null;
                }
                if (this.form.detailList[i].zhilItem2 && this.form.detailList[i].zhilItem2 != 0) {
                    const b = decimal.subtract(this.form.detailList[i].zhilItem2 || 0, this.form.detailList[i].sunhItem2 || 0);
                    const c = decimal.subtract(b, a2);
                    const d = decimal.multiply(100, c);
                    e2 = decimal.divide(d, this.form.detailList[i].zhilItem2);
                    this.form.detailList[i].sunhlItem2 = e2;
                } else {
                    this.form.detailList[i].sunhlItem2 = null;
                }
            }
            // 筛分后总质量-主表
            this.form.shaifhzzlItem1 = a1;
            this.form.shaifhzzlItem2 = a2;
            // 损耗率-主表
            this.form.sunhlItem1 = e1;
            this.form.sunhlItem2 = e2;
        },
        // 绘制图表
        setEcharts() {
            if (!this.form.detailList || this.form.detailList.length <= 0) {
                return;
            }
            const detailList = this.form.detailList;
            let data1 = [];
            let data2 = [];
            let data3 = [];
            let list = [];
            detailList.forEach((item) => {
                if (item.shaikcc && item.shaikcc.indexOf("底") == -1) {
                    list.push({
                        shaikcc: Number(item.shaikcc),
                        guidfwMin: Number(item.guidfwMin),
                        guidfwMax: Number(item.guidfwMax),
                        leijsybflPzh: Number(item.leijsybflPzh)
                    });
                }
            });
            const array = orderBy(list, ["shaikcc", "age"]);
            array.forEach((item) => {
                data1.push([item.shaikcc, item.guidfwMin]);
                data2.push([item.shaikcc, item.guidfwMax]);
                data3.push([item.shaikcc, item.leijsybflPzh]);
            });
            const chart1 = {
                data: data1,
                connectNulls: true,
                smooth: false,
                type: "line",
                lineStyle: {
                    type: "dotted"
                }
            };
            const chart2 = {
                data: data2,
                connectNulls: true,
                smooth: false,
                type: "line",
                lineStyle: {
                    type: "dotted"
                }
            };
            const chart3 = {
                data: data3,
                connectNulls: true,
                smooth: false,
                type: "line"
            };

            this.chartData.seriesData = [chart1, chart2, chart3];
            this.chartData.time = new Date().getTime();
        },
        handleKeyDown(event, rowIndex, colIndex) {
            const maxArr = [1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]; // 每一行最多有多少可聚焦输入框（从0开始）
            const ref = handleKeyDown(event, rowIndex, colIndex, maxArr);
            // 通过_拆分字符串
            const arr = ref.split("_");
            if (arr[0] > 0) {
                if (this.$refs[ref][0]) {
                    this.$refs[ref][0].focus();
                }
            } else {
                if (this.$refs[ref]) {
                    this.$refs[ref].focus();
                }
            }

        },

        // detailList粘贴赋值方法
        handlePasteDetailList(event, rowIndex, colIndex) {
            const nameAllArr = this.form.detailList.map((item, index) => {
                return ["shaikcc", "shaiszlItem1", "shaiszlItem2", "guidfwMax", "guidfwMin"]
            });
            const subscriptArr = this.form.detailList.map((item, index) => {
                return [0, 1, 2, 3, 4]
            });
            const methodsAllArr = this.form.detailList.map((item, index) => {
                return ["shaikccChange", "detailChange", "detailChange", "maxChange", "maxChange"]
            });
            const parameterArr = this.form.detailList.map((item, index) => {
                return [null, 1, 2, null, null]
            });

            const data = handlePaste(event, rowIndex, colIndex, nameAllArr, methodsAllArr, parameterArr, subscriptArr);
            const {cols, nameSetArr, methodsSetArr, parameterSetArr, subscriptSetArr} = data;
            for (let a = 0; a < nameSetArr.length; a++) {
                for (let b = 0; b < nameSetArr[a].length; b++) {
                    this.form.detailList[rowIndex + a][nameSetArr[a][b]] = cols[a][b];
                }
            }
            for (let a = 0; a < methodsSetArr.length; a++) {
                for (let b = 0; b < methodsSetArr[a].length; b++) {
                    // if (methodsSetArr[a][b] == "calculateShitzl") {
                    // console.log(methodsSetArr[a][b], subscriptArr[a][b]);

                    this.setCalculate(methodsSetArr[a][b], parameterSetArr[a][b]);
                    // } else {
                    // this.setCalculate(methodsSetArr[a][b], parameterSetArr[a][b][0], parameterSetArr[a][b][1]);
                    // }
                }
            }
        },

        // 计算方法调用
        setCalculate(name, a, b, c, d, e) {
            this[name](a, b, c, d, e);
        }
    }
};
</script>

<style scoped lang="scss">
.td-left {
  width: 15%;
}

.td1 {
  width: 85% / 11 * 1;
}

.td2 {
  width: 85% / 11 * 2;
}

.echarts-border {
  width: calc(210mm - 40mm - 8px);
  height: 150px;
  padding: 2px !important;
  background-color: #ffffff !important;
}
</style>
